package univer.oko.utilities.calendar;

import java.io.Serializable;
import java.util.Calendar;
import java.util.Iterator;
import java.util.LinkedList;

/**
 * @author Eduard Dudar
 *         Date: 29.08.2005
 *         Time: 1:58:50
 */
public class Year implements Serializable {
    private int year;
    private LinkedList months = new LinkedList();
    private Entry entry = null;

    public Year(int year) {
        this.year = year;
        for (int i = Calendar.JULY; i < Calendar.UNDECIMBER; i++) {
            months.add(new Month(i, year));
        }
        for (int i = Calendar.JANUARY; i < Calendar.JULY; i++) {
            months.add(new Month(i, year + 1));
        }
    }

    public LinkedList getMonths() {
        return this.months;
    }

    public Entry getEntry() {
        return this.entry;
    }

    public void setPayment(int month, double grn, double usd) {
        Month m = this.getMonth(month);
        if (m != null) {
            m.setPayment(grn, usd);
        }
    }

    private Month getMonth(int month) {
        for (Iterator i = this.months.iterator(); i.hasNext();) {
            Month m = (Month) i.next();
            if (m.getNumber() == month) {
                return m;
            }
        }
        return null;
    }

    public void setEntry(double grn, double usd) {
        this.entry = new Entry();
        this.entry.setPayment(grn, usd);
    }

    public int getNumber() {
        return this.year;
    }

    public String toString() {
        return "" + this.year;
    }
}
